package com.example.appcontact;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.example.base.BaseActivity;
import com.example.model.Contacts;
import com.example.util.Util;

public class A004DetailContact extends BaseActivity implements OnClickListener {
	
	private TextView tvFirstName,
	                 tvLastName,
	                 
	                 tvEmail,
	                 tvGender,
	                 tvMobile,
	                 tvAddress,
	                 tvPhone,
	                 
	                 tvCompanyEmail,
	                 tvCompanyWebsite,
	                 tvCompanyPhone,
	                 tvCompanyName,
	                 tvCompanyAddress;
	
	private TextView btBack;
	private TextView btNext;
	private Contacts data;
	private TextView tvTitle;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.detail_contact);
		data = (Contacts) (getIntent().getParcelableExtra("item"));
		initView();
		initData(data);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	private void initView() {
		
		this.btBack = (TextView)this.findViewById(R.id.header_tv_back);
		this.btNext = (TextView)this.findViewById(R.id.header_tv_next);
		this.tvTitle  = (TextView)this.findViewById(R.id.header_tv_title);
		
		tvFirstName    = (TextView)findViewById(R.id.a004_value_firstname);
		tvLastName     = (TextView)findViewById(R.id.a004_value_lastname);
		tvEmail        = (TextView)findViewById(R.id.a004_value_email);
		tvGender       = (TextView)findViewById(R.id.a004_value_gender);
		tvPhone        = (TextView)findViewById(R.id.a004_value_phone);
		tvAddress        = (TextView)findViewById(R.id.a004_value_address);
		tvMobile        = (TextView)findViewById(R.id.a004_value_mobile);
		
		tvCompanyName   = (TextView)findViewById(R.id.a004_value_company_name);
		tvCompanyPhone   = (TextView)findViewById(R.id.a004_value_company_phone);
		tvCompanyEmail   = (TextView)findViewById(R.id.a004_value_company_email);
		tvCompanyAddress = (TextView)findViewById(R.id.a004_value_company_address);
		tvCompanyWebsite   = (TextView)findViewById(R.id.a004_value_company_website);
		
		this.btNext.setVisibility(View.GONE);
		this.tvTitle.setText("Profile");
		
		btBack.setOnClickListener(this);
		
		tvPhone.setOnClickListener(this);
		tvCompanyPhone.setOnClickListener(this);
		tvEmail.setOnClickListener(this);
		
	}

	private void initData(Contacts data) {
		tvFirstName.setText(data.getFirstName());
		tvLastName.setText(data.getLastName());
		tvCompanyAddress.setText("");
		tvCompanyName.setText("");
		tvAddress.setText(data.getAddress());
		tvPhone.setText(data.getPhoneNumber());
		tvEmail.setText(data.getEmail());
		tvGender.setText(Util.decodeGenderString(data.getGender()));
		if(!TextUtils.isEmpty(tvEmail.getText().toString().trim())) {
		  	
		}
		final String number = tvPhone.getText().toString().trim();
		if(!TextUtils.isEmpty(number)) {
			
		}
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.header_tv_back:
			this.finish();
			break;
		case R.id.a004_value_email:
			if(!TextUtils.isEmpty(tvEmail.getText().toString().trim())) {
				Util.sendMail(mContext, "", data);
			}
			break;
		case R.id.a004_value_phone:
			final String number = tvPhone.getText().toString().trim();
			if(!TextUtils.isEmpty(number)) {
				Util.callPhone(mContext, number);
			}
			break;
		case R.id.a004_value_company_phone:
			final String number1 = tvCompanyPhone.getText().toString().trim();
			if(!TextUtils.isEmpty(number1)) {
				Util.callPhone(mContext, number1);
			}
			break;
		default:
			break;
		}
	}
}
